<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密码</title>
    <style>
        input {
            height: 30px;
            /* border:transparent; 透明 */  
            outline: none;  /*去掉输入文字时的*/
        }   
        a{
            display: none;  /*默认为隐藏 */
            color: red;
        }   
    </style>
</head>

<body>
    请输入密码：<input type='password'>
    <br>
    <a>请输入由字母开头，数字、大小写字母、下划线组成的长度为6~16位的字符</a>
    <script>
        let input = document.querySelector('input');
        let a = document.querySelector('a')
        input.addEventListener('input', function () {
            let regx = /^[a-zA-Z][_0-9a-zA-Z]{5,15}$/;
            if (regx.test(input.value)) {
                // input.style.borderColor = 'green';
                input.style.border = '1px solid lightgreen';
                a.style.display = "none";      
            } else {
                // input.style.borderColor = 'red';
                input.style.border = '1px solid red';
                a.style.display= 'block';           //block可以让隐藏的元素显示出来
            }
        })
    </script>
</body>

</html>